function OOB = update_oob_error_estimates(Xc,Xs,base_learner,OOB,i,subspace,settings)
% update OOB error estimates
if ~settings.bootstrap,return; end
OOB.Xc.proj = Xc(OOB.ID,subspace)*base_learner.w-base_learner.b;
OOB.Xs.proj = Xs(OOB.ID,subspace)*base_learner.w-base_learner.b;
OOB.Xc.num(OOB.ID) = OOB.Xc.num(OOB.ID) + 1;
OOB.Xc.fusion_majority_vote(OOB.ID) = OOB.Xc.fusion_majority_vote(OOB.ID)+sign(OOB.Xc.proj);
OOB.Xs.num(OOB.ID) = OOB.Xs.num(OOB.ID) + 1;
OOB.Xs.fusion_majority_vote(OOB.ID) = OOB.Xs.fusion_majority_vote(OOB.ID)+sign(OOB.Xs.proj);
% update errors
% TMP_c = OOB.Xc.fusion_majority_vote(OOB.Xc.num>0.3*i); TMP_c(TMP_c==0) = rand(sum(TMP_c==0),1)-0.5;
% TMP_s = OOB.Xs.fusion_majority_vote(OOB.Xc.num>0.3*i); TMP_s(TMP_s==0) = rand(sum(TMP_s==0),1)-0.5;
TMP_c = OOB.Xc.fusion_majority_vote; TMP_c(TMP_c==0) = rand(sum(TMP_c==0),1)-0.5;
TMP_s = OOB.Xs.fusion_majority_vote; TMP_s(TMP_s==0) = rand(sum(TMP_s==0),1)-0.5;
OOB.error = (sum(TMP_c>0)+sum(TMP_s<0))/(length(TMP_c)+length(TMP_s));

if ~ischar(OOB) && ~isempty(OOB)
    H = hist([OOB.Xc.num;OOB.Xs.num],0:max([OOB.Xc.num;OOB.Xs.num]));
    avg_L = sum(H.*(0:length(H)-1))/sum(H); % average L in OOB
    OOB.x(i) = avg_L;
    OOB.y(i) = OOB.error;
end
